package model.framework;

/**
 * SurfaceHelper provides some usefull functions for working with surfaces
 * @author geertweening
 */

public class SurfaceHelper {

	/**
	 * Finds the highest surface height in the given surface
	 * @param surface
	 * @return highest value from surface
	 */
	public int calculateHighestSurface( int[] surface, int start, int end ) {
		/* We have to start somewhere */
		int highest = surface[start];
		
		/* Find the highest surface value */
		for( int index = start+1; index < end; index++ ) {
			if( surface[ index ] > highest ) {
				highest = surface[ index ];
			}
		}
		
		return highest;
	}
	
	/**
	 * Calls calculateHighestSurface for the complete surface
	 * @param surface
	 * @return highest value from surface
	 */
	public int calculateHighestSurface( int[] surface ){
		return this.calculateHighestSurface( surface, 0, surface.length );
	}
	
	/**
	 * Finds the lowest surface height in the given surface
	 * @param surface
	 * @return lowest value from surface
	 */
	protected int calculateLowestSurface( int[] surface, int start, int end ) {
		
		/* We have to start somewhere */
		int lowest = surface[ start ];
		
		/* Find the lowest surface value */
		for( int index = start+1; index < end; index++ ) {
			if( surface[ index ] < lowest ) {
				lowest = surface[ index ];
			}
		}
		
		/* There ya go */
		return lowest;
	}
	
	/**
	 * Calls calculateLowestSurface for the complete surface
	 * @param surface
	 * @return lowest value from surface
	 */
	public int calculateLowestSurface( int[] surface ) {
		return this.calculateLowestSurface( surface, 0, surface.length );
	}

}
